package com.tocea.formation.model;

import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

@Entity
@Table(name= "Event")
public class Event implements Serializable{
	
	/**
	 * 
	 */
	private static final long serialVersionUID = -2464874179827364362L;
	
	
	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	private Integer id;
    private String nom;
    @ManyToOne
    private Person createur;
    @ManyToMany
    private Set<Person> visiteurs;
    
	public Event(Integer id, String nom, Person createur) {
		this();
		this.id = id;
		this.nom = nom;
		this.createur = createur;
	}

	public Event() {
		visiteurs= new HashSet<Person>();
	}
	
	public boolean addVisiteur(Person p){
		return visiteurs.add(p);
	}
	
	public boolean removeVisiteur(Person p){
		return visiteurs.remove(p);
	}
	
    public Set<Person> getVisiteurs() {
		return visiteurs;
	}

	public void setVisiteurs(Set<Person> visiteurs) {
		this.visiteurs = visiteurs;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ ((createur == null) ? 0 : createur.hashCode());
		result = prime * result + ((nom == null) ? 0 : nom.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Event other = (Event) obj;
		if (createur == null) {
			if (other.createur != null)
				return false;
		} else if (!createur.equals(other.createur))
			return false;
		if (nom == null) {
			if (other.nom != null)
				return false;
		} else if (!nom.equals(other.nom))
			return false;
		return true;
	}

	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public String getNom() {
		return nom;
	}

	public void setNom(String nom) {
		this.nom = nom;
	}

	public Person getCreateur() {
		return createur;
	}

	public void setCreateur(Person createur) {
		this.createur = createur;
	}

   
}
